/**
 * fileName:  FruitStructureReader.java
 * author:  lr
 * Company:  Cloudland Studio
 * Createdate:  2014-6-11 下午01:50:47
 *
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2011
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2014-6-11          lr            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.commercial.masterdata.store.read;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.cloudland.commercial.masterdata.store.DatabaseReader;
import org.cloudland.commercial.masterdata.store.entity.FruitStructureEntity;
import org.cloudland.jdbc.ibatis.masterdata.entity.PartEntity;
import org.cloudland.jdbc.ibatis.masterdata.handler.PartMapper;
import org.springframework.stereotype.Service;

 /**
 * <pre> 
 * 水果结构读取实现类
 * 使用 java.lang.Object#toString(), 或者 {@link java.lang.Character Character} 等标签
 * </pre>
 * @ClassName  FruitStructureReader
 * @author  lr
 * @version  %I%, %G%
 * @see  
 * @since   JDK1.6
 *
 */
@Service
public class FruitStructureReader implements DatabaseReader<FruitStructureEntity>  {
	
	@Resource(name = "partMapper")
	private PartMapper partMapper;
	
	/**
	 * 
	 * <pre>
	 * findById
	 * </pre>
	 *
	 * @param id 唯一标示ID
	 * @return
	 */
	public FruitStructureEntity findFruitStructureById(String id) {
		
		FruitStructureEntity entity = null;
		PartEntity entityDao = partMapper.queryPart(id);
		if (null != entityDao) {
			entity = new FruitStructureEntity(entityDao.getPartId(), entityDao.getFruitId(), entityDao.getSiteName(),entityDao.getSiteDescribe(),entityDao.getSiteType());
		}
		return entity;
	}
	
	/**
	 * <pre>
	 * 根据水果编号查询结构信息
	 * </pre>
	 *
	 * @param fruitId
	 * @return   
	 */
	public List<FruitStructureEntity> findFruitStructureByFruitId(String fruitId) {
		
		List<PartEntity> partArray = partMapper.findPartByFruitId(fruitId);
		if (null == partArray || partArray.size() <= 0) {
			return new ArrayList<FruitStructureEntity>(0);
		}
		
		List<FruitStructureEntity> result = new ArrayList<FruitStructureEntity>(partArray.size());
		FruitStructureEntity struct = null;
		for (PartEntity part : partArray) {
			struct = new FruitStructureEntity(part.getPartId(), part.getFruitId(), part.getSiteName(), part.getSiteDescribe(), part.getSiteType());
			result.add(struct);
		}
		
		return result;
	}
}
